package com.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.ocean.util.common.DateUtil;
import com.android.ocean.util.common.StringUtil;
import com.modle.ApplyFriends;
import com.modle.AuthorizeStruct;
import com.modle.BlackStruct;
import com.modle.CFriendContent;
import com.modle.CFriendLabel;
import com.modle.ChatMsgStruct;
import com.modle.GiftStruct;
import com.modle.IFriend;
import com.modle.JobStruct;
import com.modle.JobWrapperStruct;
import com.modle.PlaceStruct;
import com.modle.SkillStruct;
import com.modle.User;
import com.modle.UserAlbum;
import com.modle.UserOrgInfo;
import com.modle.UserResume;
import com.modle.UserResumeWrapper;
import com.modle.UserSkill;
import com.modle.UserVideo;
import com.modle.YzmStruct;

public class JsonUtil {
	/**
	 * 
	 * @Description:TODO解析单个用户信息
	 * @param@param obj
	 * @param@return
	 * @return User
	 * @author zhuw
	 * @throws JSONException
	 * @date 2013-8-4 下午5:25:39
	 */
	public static User parseUser(JSONObject obj) throws JSONException {
		User user = new User();
		user.id = obj.optString("id");
		user.iyrNum = obj.optString("systemNum");
		user.mobile = obj.optString("mobile");
		user.nickName = obj.optString("nickname");
		user.firstWord = obj.optString("firstWord");
		user.type = obj.optString("accountType");
		user.expireTime=obj.optString("memberExpiredAt");
		user._user_resume = obj.optString("_user_resume");
//		if (name != null) {
//			String myname = (String) new JSONObject(name).get("name");
//			user._user_resume = myname;
//		}
		
		if(!StringUtil.isNull(user.expireTime)){
			user.isMember=DateUtil.isAfterNow(user.expireTime);
			
		}
//		user.isMember = obj.optBoolean("isMember");
		user.thumb = obj.optString("avatar");

		user.male = obj.optString("sex");
		user.signature = obj.optString("signature");
		user.masterSkill = obj.optString("masterSkill");

		user.pFriVerifaciton = obj.optBoolean("friendVerification");
		user.pCanSearch = obj.optBoolean("searchAble");
		user.pAlbumViewAll = obj.optBoolean("albumsViewAll");
		user.pAlbumViewFriend = obj.optBoolean("albumsViewFriend");
		user.pAlbumViewOrg = obj.optBoolean("albumsViewOrganization");

		user.pVideoViewAll = obj.optBoolean("videoViewAll");
		user.pVideoViewFriend = obj.optBoolean("videoViewFriend");
		user.pVideoViewOrg = obj.optBoolean("videoViewOrganization");
		user.pResumeViewAll = obj.optBoolean("resumeViewAll");
		user.pResumeViewFriend = obj.optBoolean("resumeViewFriend");
		user.pResumeViewOrg = obj.optBoolean("resumeViewOrganization");

		user.setResume(parseUserResume(obj.optJSONObject("UserResume")));
	
		user.skillList = parseUserSkill(obj.optJSONArray("UserSkills"));
		user.albumList = parseUserAlbum(obj.optJSONArray("UserAlbums"));
		user.videoList = parseUserVideo(obj.optJSONArray("UserVideos"));

		user.orgInfo = parseUserOrgInfo(obj.optJSONObject("UserIntroduction"));

		return user;
	}

	/**
	 * 
	 * @Description:TODO解析简历list
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<UserResume>
	 * @author zhuw
	 * @date 2013-8-17 下午3:44:33
	 */
	public static ArrayList<UserResume> parseResumeList(JSONArray ja)
			throws JSONException {
		ArrayList<UserResume> result = null;
		if (!StringUtil.isNull(ja)) {
			result = new ArrayList<UserResume>();
			for (int i = 0; i < ja.length(); i++) {
				result.add(parseUserResume(ja.getJSONObject(i)));
			}
		}
		return result;

	}

	/**
	 * 
	 * @Description:TODO解析简历
	 * @param@param ro
	 * @param@return
	 * @return UserResume
	 * @author zhuw
	 * @throws JSONException 
	 * @date 2013-8-15 下午10:52:23
	 */
	public static UserResume parseUserResume(JSONObject ro) throws JSONException {
		UserResume ur = null;
		if (ro != null) {
			ur = new UserResume();
			ur.name = ro.optString("name");
			ur.birthDay = ro.optString("brithday");
			ur.birthPlace = ro.optString("birthplace");
			ur.livePlace = ro.optString("liveplace");
			ur.ethnic = ro.optString("ethnic");
			ur.height = ro.optString("height");
			ur.weight = ro.optString("bodyWeight");
			ur.school = ro.optString("school");
			ur.sepcialty = ro.optString("specialty");
			ur.workExp = ro.optString("workExp");

			ur.intention = ro.optString("intention");
			ur.sepcialty2 = ro.optString("specialty2");
			ur.workExp2 = ro.optString("workExp2");
			ur.workExp3 = ro.optString("workExp3");
			ur.workExp4 = ro.optString("workExp4");
			ur.workExp5 = ro.optString("workExp5");
			ur.skillDesc = ro.optString("skillDescription");
			ur.selfVal = ro.optString("valuate");
			ur.diploma = ro.optString("diploma");
			ur.gradSchool = ro.optString("graduationAt");

			JSONObject joo = ro.optJSONObject("User");
			JSONObject _joo = ro.optJSONObject("_user");
			if (joo != null) {
				ur.userID = joo.optString("id");
				//1991-11-01 00:00:00
				if(StringUtil.isNull(ur.birthDay)){
					ur.age="未知";
				}else{
					
					ur.age = StringUtil.calAge(ur.birthDay)+"";
					
				}
				ur.thumb = joo.optString("avatar");
				ur.sex = joo.optString("sex");
				ur.userInfo=parseUser(joo);
			}
			if (_joo != null) {
				ur.userID = _joo.optString("id");
				if(StringUtil.isNull(ur.birthDay)){
					ur.age="未知";
				}else{
					
					ur.age = StringUtil.calAge(ur.birthDay)+"";
					
				}
				ur.thumb = _joo.optString("avatar");
				ur.sex = _joo.optString("sex");
				ur.userInfo=parseUser(_joo);

			}
		}

		return ur;

	}

	/**
	 * 
	 * @Description:TODO解析机构信息
	 * @param@param ro
	 * @param@return
	 * @return UserResume
	 * @author zhuw
	 * @date 2013-8-22 下午11:09:07
	 */
	public static UserOrgInfo parseUserOrgInfo(JSONObject ro) {
		if (ro == null) {
			return null;
		}
		UserOrgInfo ur = new UserOrgInfo();
		ur.id = ro.optString("userId");
		ur.title = ro.optString("title");
		ur.city = ro.optString("city");
		ur.address = ro.optString("address");
		ur.desc = ro.optString("description");
		ur.mainPermitID = ro.optString("permitId");
		ur.mainPermitImg = ro.optString("permitImg");
		ur.otherPermitID = ro.optString("otherPermitId");
		ur.otherPermitImg = ro.optString("otherPermitImg");

		return ur;

	}

	/**
	 * 
	 * @Description:TODO解析技能
	 * @param@param ro
	 * @param@return
	 * @return UserSkill
	 * @author zhuw
	 * @throws JSONException
	 * @date 2013-8-15 下午10:53:14
	 */
	public static ArrayList<UserSkill> parseUserSkill(JSONArray ja)
			throws JSONException {
		ArrayList<UserSkill> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<UserSkill>();
			for (int i = 0; i < ja.length(); i++) {
				JSONObject ro = ja.getJSONObject(i);
				UserSkill ur = new UserSkill();
				ur.id = ro.optString("id");
				ur.skill = ro.optString("skill");
				list.add(ur);
			}
		}
		return list;

	}

	/**
	 * 
	 * @Description:TODO解析相册图片
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<UserAlbum>
	 * @author zhuw
	 * @date 2013-8-17 上午11:51:10
	 */
	public static ArrayList<UserAlbum> parseUserAlbum(JSONArray ja)
			throws JSONException {
		ArrayList<UserAlbum> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<UserAlbum>();
			for (int i = 0; i < ja.length(); i++) {
				JSONObject ro = ja.getJSONObject(i);
				UserAlbum ur = new UserAlbum();
				ur.id = ro.optString("id");
				ur.thumbUrl = ro.optString("thumbnailsUrl");
				ur.imgUrl = ro.optString("url");
				list.add(ur);
			}
		}
		return list;

	}

	public static ArrayList<UserVideo> parseUserVideo(JSONArray ja)
			throws JSONException {
		ArrayList<UserVideo> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<UserVideo>();
			for (int i = 0; i < ja.length(); i++) {
				JSONObject ro = ja.getJSONObject(i);
				UserVideo ur = new UserVideo();
				ur.id = ro.optString("id");
				ur.thumbUrl = ro.optString("thumbnailsUrl");
				ur.videoUrl = ro.optString("url");
				list.add(ur);
			}
		}
		return list;

	}

	/**
	 * 
	 * @Description:TODO解析招聘信息
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<JobStruct>
	 * @author zhuw
	 * @date 2013-8-17 下午3:47:10
	 */
	public static ArrayList<JobStruct> parseJobList(JSONArray ja)
			throws JSONException {
		ArrayList<JobStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<JobStruct>();
			for (int i = 0; i < ja.length(); i++) {
				list.add(parseJobStruct(ja.getJSONObject(i)));
			}
		}
		return list;

	}

	/**
	 * 
	 * @Description:TODO解析单个JOB
	 * @param@param ro
	 * @param@return
	 * @param@throws JSONException
	 * @return JobStruct
	 * @author zhuw
	 * @date 2013-8-23 下午6:27:10
	 */
	public static JobStruct parseJobStruct(JSONObject ro) throws JSONException {
		JobStruct data = null;
		if (ro != null) {
			data = new JobStruct();
			data.id = ro.optString("id");
			data.name = ro.optString("title");
			data.skills = ro.optString("skills");
			data.desc = ro.optString("description");
			data.demand = ro.optString("demand");
			data.deadline=ro.optString("deadline");
			data.pay = ro.optString("pay");
			data.cat = ro.optString("cat");
			data.createTimeStr = ro.optString("created");
			data.updateTimeStr = ro.optString("updated");
			JSONObject po = ro.optJSONObject("points");
			if (po != null) {
				data.x = po.optDouble("x");
				data.y = po.optDouble("y");
			}
			JSONObject uo = ro.optJSONObject("User");
			if (uo != null) {
				data.userID = uo.optString("id");
				data.thumb = uo.optString("avatar");
				String expireTime=uo.optString("memberExpiredAt");

				if(!StringUtil.isNull(expireTime)){
					data.uIsMember=DateUtil.isAfterNow(expireTime);
				}
				data.uType= uo.optString("accountType");
			}

			data.resumList = parseResumeWrapperList(ro.optJSONArray("Resumes"));
			if (data.resumList != null) {
				data.receRemNum = data.resumList.size() + "";
			}
		}
		return data;
	}

	/**
	 * 
	 * @Description:TODO解析礼物列表
	 * @param@param ja
	 * @param@param type判断收到还是发出的礼物
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<GiftStruct>
	 * @author zhuw
	 * @date 2013-8-24 上午12:21:41
	 */
	public static ArrayList<GiftStruct> parseGiftList(JSONArray ja, String type)
			throws JSONException {
		ArrayList<GiftStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<GiftStruct>();
			for (int i = 0; i < ja.length(); i++) {
				list.add(parseGiftStruct(ja.getJSONObject(i), type));
			}
		}
		return list;

	}

	/**
	 * 
	 * @Description:TODO解析单个Gift
	 * @param@param ro
	 * @param@return
	 * @param@throws JSONException
	 * @return JobStruct
	 * @author zhuw
	 * @date 2013-8-23 下午6:27:10
	 */
	public static GiftStruct parseGiftStruct(JSONObject ro, String type)
			throws JSONException {
		GiftStruct data = null;
		if (ro != null) {
			data = new GiftStruct();
			data.id = ro.optString("id");
			data.giftType = ro.optString("gift");
			data.giftNum = ro.optInt("quantity");
			data.msg = ro.optString("message");
			data.time = ro.optString("created");
			JSONObject jo = null;
			if (type.equalsIgnoreCase(GiftStruct.TYPE_RECEIVE)) {
				jo = ro.optJSONObject("Send");
			} else if (type.equalsIgnoreCase(GiftStruct.TYPE_SEND)) {
				jo = ro.optJSONObject("Receive");
			}
			if (jo != null) {
				data.userName = jo.optString("nickname");
				data.userThumb = jo.optString("avatar");
				data.uID = jo.optString("id");

			}

		}
		return data;
	}

	/**
	 * 获取聊天列表
	 * @param ja
	 * @param uid
	 * @param hisThumb 来者头像
	 * @param myThumb我的头像
	 * @return
	 * @throws JSONException
	 */
	public static ArrayList<ChatMsgStruct> parseChatMsgList(JSONArray ja,
			String uid,String hisThumb,String myThumb) throws JSONException {
		ArrayList<ChatMsgStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<ChatMsgStruct>();
			for (int i = ja.length() - 1; i >= 0; i--) {
				list.add(parseChatMsObj(ja.getJSONObject(i), uid,hisThumb,myThumb));
			}
		}
		return list;

	}

	/**
	 * 
	 * @Description:TODO解析单个的聊天记录
	 * @param@param ro
	 * @param@param uid
	 * @param@return
	 * @return ChatMsgStruct
	 * @author zhuw
	 * @date 2013-8-19 下午3:00:41
	 */
	public static ChatMsgStruct parseChatMsObj(JSONObject jo, String uid,String hisThumb,String myThumb) {
		ChatMsgStruct ur = new ChatMsgStruct();
		ur.id = jo.optString("id");
		ur.text = jo.optString("content");
		ur.date = jo.optString("created");
		ur.uid = jo.optString("uid");
		ur.fid = jo.optString("fid");
		if (ur.uid.equalsIgnoreCase(uid)) {
			ur.isComMeg = false;
			ur.thumb=myThumb;
		} else {
			ur.isComMeg = true;
			ur.thumb=hisThumb;
		}
		return ur;
	}

	/**
	 * 
	 * @Description:TODO解析用户列表
	 * @param@param obj
	 * @param@return
	 * @return User
	 * @author zhuw
	 * @throws JSONException
	 * @date 2013-8-4 下午5:25:34
	 */
	public static ArrayList<User> parseUserList(JSONArray ja)
			throws JSONException {
		ArrayList<User> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<User>();
			for (int i = 0; i < ja.length(); i++) {
				list.add(parseUser(ja.getJSONObject(i)));
			}

		}
		return list;
	}

	/**
	 * 
	 * @Description:TODO解析职位订阅列表
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<JobReserveStruct>
	 * @author zhuw
	 * @date 2013-8-23 下午6:22:30
	 */
	public static ArrayList<JobWrapperStruct> parseJobWrapperList(JSONArray ja)
			throws JSONException {
		ArrayList<JobWrapperStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<JobWrapperStruct>();
			for (int i = 0; i < ja.length(); i++) {
				list.add(parseJobWrapperStruct(ja.getJSONObject(i)));
			}

		}
		return list;
	}
	

	/**
	 * 
	 * @Description:TODO解析职位订阅
	 * @param@param obj
	 * @param@return
	 * @param@throws JSONException
	 * @return JobReserveStruct
	 * @author zhuw
	 * @date 2013-8-23 下午6:22:45
	 */
	public static JobWrapperStruct parseJobWrapperStruct(JSONObject obj)
			throws JSONException {

		JobWrapperStruct d = null;
		if (obj != null) {

			d = new JobWrapperStruct();
			d.id = obj.optString("id");
			d.greenChannel = obj.optBoolean("greenChannel");
			d.createTimeStr = obj.optString("created");
			JSONObject jobs = obj.optJSONObject("Jobs");
			JSONObject job = obj.optJSONObject("Job");
			if (jobs != null) {
				d.jStruct = parseJobStruct(jobs);
			} else {
				d.jStruct = parseJobStruct(job);
			}
		}
		return d;

	}
	/**
	 * 
	 * @Description:TODO解析申请加好友列表
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<ApplyFriends>
	 * @author zhuw
	 * @date 2013-11-19 下午10:01:29
	 */
	public static ArrayList<ApplyFriends> parseFriendsApplyList(JSONArray ja)
			throws JSONException {
		ArrayList<ApplyFriends> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<ApplyFriends>();
			for (int i = 0; i < ja.length(); i++) {
				list.add(parseFriendApplyStruct(ja.getJSONObject(i)));
			}
			
		}
		return list;
	}
	public static ApplyFriends parseFriendApplyStruct(JSONObject obj)
			throws JSONException {
		
		ApplyFriends d = null;
		if (obj != null) {
			
			d = new ApplyFriends();
			d.id = obj.optString("id");
			d.createTimeStr = obj.optString("created");
			JSONObject user = obj.optJSONObject("Uid");
			if (user != null) {
				d.user=parseUser(user);
			}
		}
		return d;
		
	}
	/**
	 * 
	 * @Description:TODO解析招聘信息收到的简历列表
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<ResumeWrapperStruct>
	 * @author zhuw
	 * @date 2013-8-24 下午10:35:40
	 */
	public static ArrayList<UserResumeWrapper> parseResumeWrapperList(
			JSONArray ja) throws JSONException {
		ArrayList<UserResumeWrapper> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<UserResumeWrapper>();
			for (int i = 0; i < ja.length(); i++) {
				list.add(parseResumeWrapperStruct(ja.getJSONObject(i)));
			}

		}
		return list;
	}

	/**
	 * 
	 * @Description:TODO解析招聘信息收到的单个简历
	 * @param@param obj
	 * @param@return
	 * @param@throws JSONException
	 * @return ResumeWrapperStruct
	 * @author zhuw
	 * @date 2013-8-24 下午10:36:22
	 */
	public static UserResumeWrapper parseResumeWrapperStruct(JSONObject obj)
			throws JSONException {

		UserResumeWrapper d = null;
		if (obj != null) {

			d = new UserResumeWrapper();
			d.id = obj.optString("id");
			d.greenChannel = obj.optBoolean("greenChannel");
			d.createTimeStr = obj.optString("created");
			JSONObject jo = obj.optJSONObject("userResume");
			if (jo != null) {
				d.rStruct = parseUserResume(jo);
			}
		}
		return d;
	}

	/**
	 * 
	 * @Description:TODO解析通讯录
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<IContract>
	 * @author zhuw
	 * @date 2013-8-4 下午10:37:32
	 */
	public static ArrayList<IFriend> parseFriendsList(JSONArray ja)
			throws JSONException {
		ArrayList<IFriend> list = null;
		if (!StringUtil.isNull(ja)) {
			HashMap<String, ArrayList<User>> map = new HashMap<String, ArrayList<User>>();

			for (int i = 0; i < ja.length(); i++) {
				User tempU = parseUser(ja.getJSONObject(i));
				if (map.containsKey(tempU.firstWord)) {
					map.get(tempU.firstWord).add(tempU);
				} else {
					ArrayList<User> tempList = new ArrayList<User>();
					tempList.add(tempU);
					map.put(tempU.firstWord, tempList);
				}
			}
			list = covertMapToIContractList(map);

		}
		return list;
	}

	/**
	 * 
	 * @Description:TODO将map解析分类为List的通讯录
	 * @param@param map
	 * @param@return
	 * @return ArrayList<IContract>
	 * @author zhuw
	 * @date 2013-8-4 下午10:36:12
	 */
	private static ArrayList<IFriend> covertMapToIContractList(
			HashMap<String, ArrayList<User>> map) {
		ArrayList<IFriend> list = null;
		if (map != null && map.size() > 0) {
			list = new ArrayList<IFriend>();
			Set<String> keys = map.keySet();
			Iterator<String> it = keys.iterator();
			while (it.hasNext()) {
				String key = it.next();
				list.add(new CFriendLabel(key));
				for (User tu : map.get(key)) {
					list.add(new CFriendContent(tu));
				}
			}
		}
		return list;

	}

	/**
	 * 
	 * @Description:TODO黑名单列表
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<BlackStruct>
	 * @author zhuw
	 * @date 2013-9-1 上午10:47:51
	 */
	public static ArrayList<BlackStruct> parseBlackList(JSONArray ja)
			throws JSONException {
		ArrayList<BlackStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<BlackStruct>();
			for (int i = 0; i < ja.length(); i++) {
				list.add(parseBlackStruct(ja.getJSONObject(i)));
			}
		}
		return list;

	}
	/**
	 * 
	 * @Description:TODO解析未读消息
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<User>
	 * @author zhuw
	 * @date 2013-11-2 下午10:04:32
	 */
	public static ArrayList<User> parseNoReadMsgList(JSONArray ja,String userType)
			throws JSONException {
		ArrayList<User> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<User>();
			for (int i = 0; i < ja.length(); i++) {
				User u=parseNoReadMsgStruct(ja.getJSONObject(i),userType);
				if(u!=null){
					list.add(u);
				}
			}
		}
		return list;
		
	}
	/**
	 * 
	 * @Description:TODO解析未读消息
	 * @param@param ro
	 * @param@return
	 * @param@throws JSONException
	 * @return User
	 * @author zhuw
	 * @date 2013-11-2 下午10:04:22
	 */
	public static User parseNoReadMsgStruct(JSONObject ro,String userType)
			throws JSONException {
		User result = null;
		if (ro != null) {
			User data=parseUser(ro.optJSONObject("user"));
			if(data!=null&&data.type.equalsIgnoreCase(userType)){
			data.msgTotalNum = ro.optString("total");
			JSONObject jo=ro.optJSONObject("0");
			if(jo!=null){
				
				data.msgType= jo.optString("type");
				data.msgContent= jo.optString("content");
		     	data.recetime = jo.optString("created");
				data.isRead = false;
				
			}
			result=data;
		}
		}
		return result;
	}
	/**
	 * 
	 * @Description:TODO解析黑名单个体
	 * @param@param ro
	 * @param@return
	 * @param@throws JSONException
	 * @return BlackStruct
	 * @author zhuw
	 * @date 2013-9-1 上午10:47:35
	 */
	public static BlackStruct parseBlackStruct(JSONObject ro)
			throws JSONException {
		BlackStruct data = null;
		if (ro != null) {
			data = new BlackStruct();
			data.bid = ro.optString("id");

			JSONObject jo = ro.optJSONObject("Tid");
			if (jo != null) {
				data.uid = jo.optString("id");
				data.nickname = jo.optString("nickname");
				data.signature = jo.optString("signature");
				data.uid = jo.optString("uid");
				data.thumb = jo.optString("avatar");
				JSONObject reo = jo.optJSONObject("UserResume");
				if (reo != null) {
					data.liveplace = reo.optString("liveplace");
				}
			}
		}
		return data;
	}
	/**
	 * 
	 * @Description:TODO解析验证码
	 * @param@param ro
	 * @param@return
	 * @param@throws JSONException
	 * @return YzmStruct
	 * @author zhuw
	 * @date 2013-9-9 下午10:12:13
	 */
	public static YzmStruct parseYzmStruct(JSONObject ro)
			throws JSONException {
		YzmStruct data = null;
		if (ro != null) {
			data = new YzmStruct();
			data.mobile = ro.optString("mobile");
			data.verifyCode = ro.optString("verifyCode");
		}
		return data;
	}
	/**
	 * 
	 * @Description:TODO解析权限
	 * @param@param ro
	 * @param@return
	 * @param@throws JSONException
	 * @return AuthorizeStruct
	 * @author zhuw
	 * @date 2013-9-29 下午10:43:28
	 */
	public static AuthorizeStruct parseAuthorizeStruct(JSONObject ro)
			throws JSONException {
		AuthorizeStruct data = null;
		if (ro != null) {
			data = new AuthorizeStruct();
			data.canViewAlbum = ro.optBoolean("albumsView");
			data.canViewVideo = ro.optBoolean("videoView");
			data.canViewResume = ro.optBoolean("resumeView");
		}
		return data;
	}
	/**
	 * 
	 * @Description:TODO读取技能树
	 * @param@param ja
	 * @param@return
	 * @param@throws JSONException
	 * @return ArrayList<UserSkill>
	 * @author zhuw
	 * @date 2013-8-20 下午10:18:27
	 */
	public static ArrayList<SkillStruct> readSkillTree(JSONArray ja)
			throws JSONException {
		ArrayList<SkillStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<SkillStruct>();
			for (int i = 0; i < ja.length(); i++) {
				JSONObject ro = ja.getJSONObject(i);
				SkillStruct ur = new SkillStruct();
				ur.name = ro.optString("n");
				ur.keyIndex=ro.optString("key");
				ur.childList = readSkillTree(ro.optJSONArray("list"));
				list.add(ur);
			}
		}
		return list;

	}
	public static ArrayList<SkillStruct> readLocalSubCat(JSONArray ja)
			throws JSONException {
		ArrayList<SkillStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<SkillStruct>();
			for (int i = 0; i < ja.length(); i++) {
				JSONObject ro = ja.getJSONObject(i);
				SkillStruct ur = new SkillStruct();
				ur.name = ro.optString("n");
				ur.keyIndex = ro.optString("key");
				if(SpJobSubscriptionUtil.localSubMap.containsKey(ur.keyIndex)){
					ur.isLocalSave=true;
				}
//				ur.childList = readSkillTree(ro.optJSONArray("list"));
				list.add(ur);
			}
		}
		return list;
		
	}

	/**
	 * 
	 * @Description:TODO按照关键字读取技能搜索结果
	 * @param@param str
	 * @param@param keywords
	 * @param@return
	 * @return ArrayList<SkillStruct>
	 * @author zhuw
	 * @date 2013-8-15 下午10:21:43
	 */
	public static ArrayList<SkillStruct> readSearSkill(String str,
			String keywords) {
		ArrayList<SkillStruct> list = new ArrayList<SkillStruct>();
		String[] array = str.split("-");
		for (int i = 0; i < array.length; i++) {
			if (array[i].contains(keywords)) {
				list.add(new SkillStruct(array[i]));
			}
		}
		return list;
	}

	public static ArrayList<PlaceStruct> readPlaceTree(JSONArray ja)
			throws JSONException {
		ArrayList<PlaceStruct> list = null;
		if (!StringUtil.isNull(ja)) {
			list = new ArrayList<PlaceStruct>();
			for (int i = 0; i < ja.length(); i++) {
				JSONObject ro = ja.getJSONObject(i);
				PlaceStruct ur = new PlaceStruct();
				ur.name = ro.optString("n");
				ur.childList = readPlaceTree(ro.optJSONArray("list"));
				list.add(ur);
			}
		}
		return list;

	}

	/**
	 * 
	 * @Description:TODO解析地点
	 * @param@param jsonStr
	 * @param@return
	 * @return ArrayList<PlaceStruct>
	 * @author zhuw
	 * @date 2013-8-15 下午5:47:28
	 */
	public static ArrayList<PlaceStruct> readPlace(String jsonStr) {
		ArrayList<PlaceStruct> list = new ArrayList<PlaceStruct>();
		try {
			JSONObject jo = new JSONObject(jsonStr);
			if (jo != null) {

				Iterator<String> its = jo.keys();
				while (its.hasNext()) {
					PlaceStruct ps = new PlaceStruct();

					String key = its.next();
					String places = jo.optString(key);
					String placesArray[] = places.split("-");
					ArrayList<PlaceStruct> childList = new ArrayList<PlaceStruct>();
					for (int i = 0; i < placesArray.length; i++) {
						PlaceStruct childPs = new PlaceStruct(placesArray[i]);
						childList.add(childPs);
					}
					ps.name = key;
					ps.childList = childList;
					list.add(ps);
				}

			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;

	}
    /**
     * 
     * @Description:TODO解析分类查看列表
     * @param@param ja
     * @param@return
     * @param@throws JSONException
     * @return HashMap<String,String>
     * @author zhuw
     * @date 2013-9-5 下午3:27:56
     */
	public static HashMap<String, String> parseCatCountMap(JSONArray ja)
			throws JSONException {
		HashMap<String, String> map = new HashMap<String, String>();
		for (int i = 0; i < ja.length(); i++) {
			JSONObject jo = ja.getJSONObject(i);
			map.put(jo.optString("cat"), jo.optString("catCount"));
		}
		return map;

	}
	
	

	/**
	 * 解析400错误
	 * 
	 * @param obj
	 * @return
	 */
	// public static String parse400(JSONObject obj) throws JSONException {
	// StringBuffer sb = new StringBuffer();
	// Iterator<String> it = obj.keys();
	// while (it.hasNext()) {
	// String key = it.next();
	// sb.append(key);
	// JSONArray ja = obj.getJSONArray(key);
	// for (int i = 0; i < ja.length(); i++) {
	// sb.append(ja.get(i) + "\n");
	// }
	// }
	// return sb.toString();
	// }

}
